home *** CD-ROM | disk | FTP | other *** search
/ EnigmA Amiga Run 1996 March / EnigmA AMIGA RUN 05 (1996)(G.R. Edizioni)(IT)[!][issue 1996-03][Skylink CD IV].iso / earcd / program / ixemlsrc.lha / ixemul / library / __close.c < prev    next >
C/C++ Source or Header  |  1995-12-23  |  2KB  |  77 lines

  1. /*
  2.  *  This file is part of ixemul.library for the Amiga.
  3.  *  Copyright (C) 1991, 1992  Markus M. Wild
  4.  *
  5.  *  This library is free software; you can redistribute it and/or
  6.  *  modify it under the terms of the GNU Library General Public
  7.  *  License as published by the Free Software Foundation; either
  8.  *  version 2 of the License, or (at your option) any later version.
  9.  *
  10.  *  This library is distributed in the hope that it will be useful,
  11.  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
  12.  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
  13.  *  Library General Public License for more details.
  14.  *
  15.  *  You should have received a copy of the GNU Library General Public
  16.  *  License along with this library; if not, write to the Free
  17.  *  Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  18.  *
  19.  *  $Id: __close.c,v 1.2 1994/06/19 15:18:48 rluebbert Exp $
  20.  *
  21.  *  $Log: __close.c,v $
  22.  *  Revision 1.2  1994/06/19  15:18:48  rluebbert
  23.  *  *** empty log message ***
  24.  *
  25.  */
  26.  
  27. #define KERNEL
  28. #include "ixemul.h"
  29. #include "kprintf.h"
  30.  
  31. int
  32. __close(struct file *f)
  33. {
  34.   ix_lock_base ();
  35.  
  36.   f->f_count--;
  37.  
  38.   KPRINTF (("__close: closing file $%lx, f_count now %ld.\n", f, f->f_count));
  39.   if (f->f_count > 0) goto unlock;
  40.   /* don't need file locking here... if the counter is down to 0, nobody
  41.      else CAN have this file locked */
  42.   __wait_packet(&f->f_sp);
  43.  
  44.   if (!(f->f_flags & FEXTOPEN))
  45.     __Close (CTOBPTR (f->f_fh));
  46.  
  47.   /* if we have to set some modes, do it now */
  48.   if (f->f_stb_dirty)
  49.     {
  50.       syscall (SYS_chmod, f->f_name, f->f_stb.st_mode);
  51.       /* should later also set modification time */
  52.     }
  53.  
  54.   if (f->f_flags & FUNLINK) syscall (SYS_unlink, f->f_name);
  55.  
  56.   /* NOTE: the FEXTOPEN flag tells us two things: 1) we shouldn't
  57.    * perform a Close() on the filehandle, and 2) the name in the
  58.    * file structure wasn't allocated by malloc(), so we shouldn't 
  59.    * free() it either. */
  60.   if (!(f->f_flags & FEXTOPEN) && f->f_name) 
  61.     {
  62.       KPRINTF (("f->f_name(%s) ", f->f_name));
  63.       kfree (f->f_name);
  64.     }
  65.  
  66.   if (f->f_async_len) 
  67.     {
  68.       KPRINTF (("f->f_async_len "));
  69.       kfree (f->f_async_buf);
  70.     }
  71.  
  72. unlock:
  73.   ix_unlock_base ();
  74.  
  75.   return 0;
  76. }
  77.